package com.yyf.handler;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
//import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * company: www.abc.com
 * Author: Administrator
 * Create Data: 2020/11/25 0025
 */

// 定义处理器类
@Controller
@RequestMapping("/some")//命名空间


public class SomeHandler {
@RequestMapping("/first")
    public ModelAndView  doFirst(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mv = new ModelAndView();
        //设置响应中的模型
        //相当于request.setAttribute("message","Hello SpringMVC!")
        mv.addObject("message","Hello SpringMVC!");
        //设置响应视图
        mv.setViewName("welcome");
        return mv;
    }
    @RequestMapping("/second")
    public ModelAndView  doSecond(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mv = new ModelAndView();
        //设置响应中的模型
        //相当于request.setAttribute("message","Hello SpringMVC!")
        mv.addObject("message","执行doseond方法");
        //设置响应视图
        mv.setViewName("welcome");
        return mv;
    }
    //@RequestMapping("/third*")//要求请求资源路径名称以third开头
    //@RequestMapping("/*third")//要求请求资源路径名称以third结尾
    //@RequestMapping("/*/third")//要求命名空间路径和请求资源路径名称之间必须有一级路径
    @RequestMapping("/**/third")//要求命名空间路径和请求资源路径名称之间必须有一级路径
    public ModelAndView  doThird(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mv = new ModelAndView();
        //设置响应中的模型
        //相当于request.setAttribute("message","Hello SpringMVC!")
        mv.addObject("message", "执行doThird方法");
        //设置响应视图
        mv.setViewName("welcome");
        return mv;
    }
    //method限制请求方式为post
    @RequestMapping(value="fourth" ,method= RequestMethod.POST)//要求命名空间路径和请求资源路径名称之间必须有一级路径
    public ModelAndView  doFourth(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mv = new ModelAndView();
        //设置响应中的模型
        //相当于request.setAttribute("message","Hello SpringMVC!")
        mv.addObject("message", "执行dofourth方法");
        //设置响应视图
        mv.setViewName("welcome");
        return mv;
    }
    //@RequestMapping(value="/fifth" ,params="name")//要求请求中必须携带name参数，即访问时some/fifth/?name=aaa
    //@RequestMapping(value="/fifth" ,params={"name","age"})//要求请求中必须携带name参数和age参数，即访问时some/fifth/?name=aaa&age=20
    @RequestMapping(value="/fifth" ,params={"!name","age"})
    public ModelAndView  doFifth(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mv = new ModelAndView();
        //设置响应中的模型
        //相当于request.setAttribute("message","Hello SpringMVC!")
        mv.addObject("message", "执行dofifth方法");
        //设置响应视图
        mv.setViewName("welcome");
        return mv;
    }
}
